<?
	mysql_connect("localhost","root","root");
	mysql_select_db("database");
	mysql_query("SET NAMES UTF8");
	
	if(trim($_POST["UsName"]) == "")
	{
		echo "Please input Username !";
		echo "<br> Go to <a href='register.php'>Back</a>";
		exit();	
	}
	if(trim($_POST["Name"]) == "")
	{
		echo "Please input Name !";
		echo "<br> Go to <a href='register.php'>Back</a>";
		exit();	
	}
	if(strlen($password)<6 or strlen($password)>15)
	{	
		echo "Please input password and minimum 6 charactor !";
		echo "<br> Go to <a href='register.php'>Back</a>";
		exit();	
	}	
		
	if($_POST["password"] != $_POST["re-pass"])
	{
		echo "Password not Match !";
		echo "<br> Go to <a href='register.php'>Back</a>";
		exit();
	}
	
	if(trim($_POST["email"]) == "")
	{
		echo "Please input E-mail !";
		echo "<br> Go to <a href='register.php'>Back</a>";
		exit();	
	}	

	if(trim($_POST["add"]) == "")
	{
		echo "Please input Address !";
		echo "<br> Go to <a href='register.php'>Back</a>";
		exit();	
	}	

	if(trim($_POST["phone"]) == "")
	{
		echo "Please input Phone Numder !";
		echo "<br> Go to <a href='register.php'>Back</a>";
		exit();	
	}	
	
	$strSQL = "SELECT * FROM member WHERE u_name = '".trim($_POST['UsName'])."' ";
	$objQuery = mysql_query($strSQL);
	$objResult = mysql_fetch_array($objQuery);
	mysql_query("SET NAMES UTF8");
	if($objResult)
	{
			echo "Username already exists!";
			echo "<br> Go to <a href='register.php'>Back</a>";
	}
	else
	{	
		
		$strSQL = "INSERT INTO member (u_name,name,pass,address,email,tel) VALUES ('".$_POST["UsName"]."', 
		'".$_POST["Name"]."','".$_POST["password"]."','".$_POST["add"]."','".$_POST["email"]."','".$_POST["phone"]."')";
		$objQuery = mysql_query($strSQL);
		mysql_query("SET NAMES UTF8");
		
		header("location:signup-cfirm.php");		
	}

	mysql_close();
?>